//package com.ruoyi.web.controller.cs;
//
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import com.ruoyi.common.annotation.CheckSwitch;
//import com.ruoyi.common.constant.Constants;
//import com.ruoyi.common.core.controller.BasicsController;
//import com.ruoyi.common.core.domain.Response;
//import com.ruoyi.common.core.domain.entity.SysDictData;
//import com.ruoyi.common.core.domain.entity.SysUser;
//import com.ruoyi.common.core.domain.model.LoginUser;
//import com.ruoyi.common.core.page.ResponsePageInfo;
//import com.ruoyi.common.utils.DateUtils;
//import com.ruoyi.common.utils.ServletUtils;
//import com.ruoyi.cs.domain.TGoods;
//import com.ruoyi.cs.domain.TMineClear;
//import com.ruoyi.cs.domain.vo.TBoxVo;
//import com.ruoyi.cs.service.ITGoodsService;
//import com.ruoyi.framework.web.service.TokenService;
//import com.ruoyi.system.mapper.SysDictDataMapper;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.models.auth.In;
//import org.springframework.cache.annotation.Cacheable;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//import com.ruoyi.common.annotation.Log;
//import com.ruoyi.common.enums.BusinessType;
//import com.ruoyi.cs.service.ITMineClearService;
//
//import javax.validation.constraints.Min;
//import javax.validation.constraints.NotNull;
//
///**
// * 排雷记录Controller
// *
// * @author liuzhisheng
// * @date 2022-12-13
// */
//@Api(tags = {"全名挑战模块"})
//@RestController
//@RequestMapping("/cs/mineClear")
//@SuppressWarnings("all")
//public class TMineClearController extends BasicsController
//{
//    @Autowired
//    private ITMineClearService tMineClearService;
//    @Autowired
//    private ITGoodsService tGoodsService;
//    @Autowired
//    private SysDictDataMapper sysDictDataMapper;
//    @Autowired
//    private TokenService tokenService;
//
//    /**
//     * 全名挑战饰品列表
//     */
//    @ApiOperation("后台全名挑战饰品列表")
//    @PreAuthorize("@ss.hasPermi('cs:mineClear:goodsList')")
//    @RequestMapping(name="后台全名挑战饰品列表",value="goodsList",method = RequestMethod.POST)
//    public ResponsePageInfo<TGoods> luckyListBack(@RequestBody TGoods tGoods)
//    {
//        startPage(tGoods.getPageNum(), tGoods.getPageSize());
//        tGoods.setBackStage(Constants.BACKSTAGE);
//        tGoods.setGoodsBelongingType(Constants.GOOGSBLTYPE10);
//        tGoods.setWhetherFloors(1);
//        List<TGoods> list = tGoodsService.selectTGoodsList(tGoods);
//        return toResponsePageInfo(list);
//    }
//
//    /**
//     * 默认保底饰品查询
//     */
//    @ApiOperation("后台默认保底饰品查询")
//    @PreAuthorize("@ss.hasPermi('cs:mineClear:defaultTGoods')")
//    @RequestMapping(name="后台默认保底饰品查询",value="defaultTGoods",method = RequestMethod.GET)
//    public Response<SysDictData> defaultTGoods()
//    {
//        SysDictData ss = sysDictDataMapper.selectDictDataById(366L);
//        return Response.success(ss);
//    }
//
//    /**
//     * 默认保底饰品编辑
//     */
//    @ApiOperation("后台默认保底饰品编辑")
//    @PreAuthorize("@ss.hasPermi('cs:mineClear:defaultTGoodsSet')")
//    @RequestMapping(name="后台默认保底饰品编辑",value="defaultTGoodsSet",method = RequestMethod.GET)
//    @Log(title = "后台默认保底饰品编辑", businessType = BusinessType.UPDATE)
//    @ApiImplicitParam(name = "value",value = "饰品id" ,dataType = "String", paramType = "query", required = false)
//    public Response<Integer> defaultTGoodsSet(String value)
//    {
//        TGoods tGoods = tGoodsService.defaultTGoodsSetMineClear(value);
//        int row = sysDictDataMapper.updateDefualtValueMineClear(value,"366",tGoods.getGoodsId(),tGoods.getGoodsName());
//        return toResponse(row);
//    }
//
//    /**
//     * 扫雷统计
//     */
//    @ApiOperation("后台扫雷统计")
//    @PreAuthorize("@ss.hasPermi('cs:mineClear:count')")
//    @RequestMapping(name="后台扫雷统计",value="count",method = RequestMethod.GET)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "startTime",value = "开始时间" , dataType = "String", paramType = "query", required = false),
//            @ApiImplicitParam(name = "endTime",value = "结束时间" , dataType = "String", paramType = "query", required = false),
//    })
//    public Response<HashMap> count(String startTime,String endTime)
//    {
//       return tMineClearService.count(startTime,endTime);
//    }
//
//    /**
//     * 排雷记录列表
//     */
//    @PreAuthorize("@ss.hasPermi('cs:mineClear:backList')")
//    @ApiOperation("后台排雷记录列表")
//    @RequestMapping(name="后台排雷记录列表",value="listBack",method = RequestMethod.POST)
//    public ResponsePageInfo<TMineClear> listBack(@RequestBody TMineClear tMineClear)
//    {
//        startPage(tMineClear.getPageNum(),tMineClear.getPageSize());
//        List<TMineClear> list = tMineClearService.selectTMineClearList(tMineClear);
//        if (list.size() > 0){
//            for (TMineClear mineClear : list) {
//                String challengeResult = "";
//                int challengeLayer = mineClear.getChallengeLayer().intValue();
//                switch(mineClear.getStatus().intValue()){
//                    case 0:
//                        challengeResult = "第"+challengeLayer+"层挑战中";
//                        break;
//                    case 1:
//                        challengeResult = "爆炸在第"+challengeLayer+"层";
//                        break;
//                    case 2:
//                        challengeResult = "放弃在第"+challengeLayer+"层";
//                        break;
//                    case 3:
//                        challengeResult = "全通关";
//                        break;
//                }
//                mineClear.setChallengeResult(challengeResult);
//            }
//        }
//        return toResponsePageInfo(list);
//    }
//
//    /**
//     * 排雷详情
//     */
//    @ApiOperation("后台排雷详情")
//    @PreAuthorize("@ss.hasPermi('cs:mineClear:info')")
//    @RequestMapping(name="后台排雷详情",value="info",method = RequestMethod.GET)
//    @ApiImplicitParam(name = "id",value = "排雷编号" , dataType = "String", paramType = "query", required = true)
//    public Response<TMineClear> info(String id)
//    {
//        return tMineClearService.info(id);
//    }
//
//    /**-----------------------------------------前端----------------------------------**/
//    /**
//     * 全名挑战
//     */
//    @ApiOperation("全名挑战")
//    @RequestMapping(name="全名挑战",value="fullNameChallenge",method = RequestMethod.GET)
//    public Response<TMineClear> fullNameChallenge()
//    {
//        /**获取登录用户*/
//        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
//        if (loginUser == null || loginUser.getUser() == null){
//            return Response.fail("请登录!");
//        }
//        String userId = loginUser.getUser().getLoginUserId();
//        return tMineClearService.fullNameChallenge(userId);
//    }
//
//    /**
//     * 开始挑战
//     */
//    @CheckSwitch
//    @ApiOperation("开始挑战")
//    @RequestMapping(name="开始挑战",value="startChallenge",method = RequestMethod.GET)
//    @Log(title = "全名挑战开始挑战", businessType = BusinessType.OTHER)
//    public Response<String> startChallenge()
//    {
//        /**获取登录用户*/
//        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
//        if (loginUser == null || loginUser.getUser() == null){
//            return Response.fail("请登录!");
//        }
//        String userId = loginUser.getUser().getLoginUserId();
//        return tMineClearService.startChallenge(userId);
//    }
//
//    /**
//     * 开始通关
//     */
//    @CheckSwitch
//    @ApiOperation("开始通关")
//    @RequestMapping(name="开始通关",value="startAdopt",method = RequestMethod.GET)
//    @ApiImplicitParam(name = "position",value = "选择位置 从1开始" , dataType = "int", paramType = "query", required = true)
//    @Log(title = "全名挑战开始通关", businessType = BusinessType.OTHER)
//    public Response<TMineClear> startAdopt(@Min(value = 1,message = "请选择区位") Integer position)
//    {
//        /**获取登录用户*/
//        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
//        if (loginUser == null || loginUser.getUser() == null){
//            return Response.fail("请登录!");
//        }
//        String userId = loginUser.getUser().getLoginUserId();
//        if(position == null){
//            return Response.fail("请选择!");
//        }
//        if(position == 0){
//            return Response.fail("请从1格开始!");
//        }
//        return tMineClearService.startAdopt(userId,position-1);
//    }
//
//    /**
//     * 放弃挑战
//     */
//    @CheckSwitch
//    @ApiOperation("放弃挑战")
//    @RequestMapping(name="放弃挑战",value="waiver",method = RequestMethod.GET)
//    @Log(title = "全名挑战放弃挑战", businessType = BusinessType.OTHER)
//    public Response<TMineClear> waiver()
//    {
//        /**获取登录用户*/
//        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
//        if (loginUser == null || loginUser.getUser() == null){
//            return Response.fail("请登录!");
//        }
//        String userId = loginUser.getUser().getLoginUserId();
//        return tMineClearService.waiver(userId);
//    }
//
//    /**
//     * 是否复活挑战
//     */
//    @CheckSwitch
//    @ApiOperation("是否复活挑战")
//    @RequestMapping(name="是否复活挑战",value="riseChallenge",method = RequestMethod.GET)
//    @ApiImplicitParam(name = "type",value = "类型 0 复活挑战  1 放弃复活" , dataType = "string", paramType = "query", required = true)
//    @Log(title = "全名挑战是否复活挑战", businessType = BusinessType.OTHER)
//    public Response<TMineClear> riseChallenge(String type)
//    {
//        /**获取登录用户*/
//        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
//        if (loginUser == null || loginUser.getUser() == null){
//            return Response.fail("请登录!");
//        }
//        String userId = loginUser.getUser().getLoginUserId();
//        return tMineClearService.riseChallenge(userId,type);
//    }
//
//    @ApiOperation("扫雷排名")
//    @GetMapping("/mineClearRanking")
//    @ApiImplicitParam(name = "type",value = "类型 today 今日 yesterday 昨日" ,dataType = "String", paramType = "query", required = true)
//    @Cacheable(value="oneSecondCache", key="'mineClearRanking'+#p0")
//    public Response<Map> mineClearRanking(String type){
//        LoginUser loginUser = tokenService.getLoginUserWeb(ServletUtils.getRequest());
//        String userId = null;
//        if(loginUser != null){
//            SysUser sysUser = loginUser.getUser();
//            userId = sysUser.getLoginUserId();
//        }
//        Map map = tMineClearService.mineClearRanking(type,userId);
//        return Response.success(map);
//    }
//}
